10  Scatter Plot

10.1 Calculation

library(lagci)
Warning in fun(libname, pkgname): mzR has been built against a different Rcpp version (1.0.14)
than is installed on your system (1.1.0). This might lead to errors
when loading mzR. If you encounter such issues, please send a report,
including the output of sessionInfo() to the Bioc support forum at 
https://support.bioconductor.org/. For details see also
https://github.com/sneumann/mzR/wiki/mzR-Rcpp-compiler-linker-issue.
── Attaching packages ────────────────────────────────────────── lagci 0.99.5 ──
✔ dplyr   1.1.4     ✔ ggplot2 3.5.2
── Conflicts ────────────────────────────────────────────── lagci_conflicts() ──
✖ methods::body<-()    masks base::body<-()
✖ dplyr::filter()      masks stats::filter()
✖ methods::kronecker() masks base::kronecker()
✖ dplyr::lag()         masks stats::lag()
data("heart_data")
data("step_data")
result <- lagci::calculate_lagged_correlation(
  y = heart_data$heart,
  x = step_data$step,
  time2 = heart_data$time,
  time1 = step_data$time,
  time_tol = 0.5,
  step = 1/60,
  align_method = "linear",
  cor_method = "spearman"
)

10.2 Scatter Plot

To interpret, compare how tight the cloud is at the peak lag versus the global view: a noticeably tighter, monotonic pattern at the peak lag supports a genuine lagged relationship; similar patterns across both views suggest mainly contemporaneous variation or a weak/unstable lag. If desired, you can overlay a smooth trend with + ggplot2::geom_smooth(method = "loess", se = FALSE) and export with ggplot2::ggsave(...).

max_scatter <- lagged_scatter_plot(object = result,
                    x_name = "x_name",
                    y_name = "y_name",
                    which = "max",
                    hex = TRUE)

global_scatter <- lagged_scatter_plot(object = result,
                    x_name = "x_name",
                    y_name = "y_name",
                    which = "global",
                    hex = TRUE)

hex_no <- lagged_scatter_plot(object = result,
                    x_name = "x_name",
                    y_name = "y_name",
                    which = "max",
                    hex = FALSE)

max_scatter;global_scatter;hex_no
Warning: The dot-dot notation (`..count..`) was deprecated in ggplot2 3.4.0.
ℹ Please use `after_stat(count)` instead.
ℹ The deprecated feature was likely used in the lagci package.
  Please report the issue to the authors.
`geom_smooth()` using formula = 'y ~ x'

`geom_smooth()` using formula = 'y ~ x'

`geom_smooth()` using formula = 'y ~ x'